const express = require('express');
const projectController = require('../controllers/projectController');
const { protect, optionalProtect } = require('../middlewares/authMiddleware');

const router = express.Router();

// 公开路由（可选保护，登录用户可以获取更多信息）
router.use(optionalProtect);
router.get('/public', projectController.getPublicProjects);

// 保护的路由（需要登录）
router.use(protect);

router.post('/', projectController.createProject);
router.get('/user/:userId', projectController.getUserProjects);
router.get('/user', projectController.getUserProjects);

router
  .route('/:id')
  .get(projectController.getProject)
  .patch(projectController.updateProject)
  .delete(projectController.deleteProject);

router.post('/:id/like', projectController.likeProject);
router.get('/:id/history', projectController.getProjectHistory);
router.post('/:id/restore/:version', projectController.restoreProjectVersion);

// 协作者管理
router.post('/:id/collaborators', projectController.addCollaborator);
router.patch('/:id/collaborators', projectController.updateCollaborator);
router.delete('/:id/collaborators/:userId', projectController.removeCollaborator);

module.exports = router;